package com.gongj.rabbit.ttl;

import com.gongj.rabbit.utils.RabbitMQUtil;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class Provider {
    public static void main2(String[] args) throws IOException {
        // 获取连接对象
        Connection conn = RabbitMQUtil.createConn();
        // 获取连接通道
        Channel channel = conn.createChannel();
        Map<String,Object> map = new HashMap<>();
        //给队列设置ttl
        map.put("x-message-ttl",10000);
        channel.queueDeclare("ttl-quequ",true,false,true,map);
    }

    public static void main3(String[] args) throws IOException {
        // 获取连接对象
        Connection conn = RabbitMQUtil.createConn();
        // 获取连接通道
        Channel channel = conn.createChannel();
        //给消息设置ttl
        channel.queueDeclare("ttl-quequ2",true,false,true,null);

        channel.basicPublish("","ttl-quequ2",
                new AMQP.BasicProperties().builder()
                        .expiration("30000")
                        .build(),
                "设置消息过期时间".getBytes());
    }

    public static void main(String[] args) throws IOException {
        // 获取连接对象
        Connection conn = RabbitMQUtil.createConn();
        // 获取连接通道
        Channel channel = conn.createChannel();
        /**
         * 参数1: 交换机名称
         * 参数2: 交换机类型  fanout 广播类型
         */
        // 声明fanout交换机(不存在时会创建)
        //channel.exchangeDeclare("ttl-fanout", BuiltinExchangeType.FANOUT);
        Map<String, Object> map = new HashMap<>();
        //map.put ("x-expires" , 40000);
        //给队列设置ttl
        channel.queueDeclare("ttl-quequ3",true,false,true,map);
        channel.basicPublish("","ttl-quequ3",
                null,
                "设置队列过期时间".getBytes());
    }
}
